package com.martin.dms.model.hib;

import java.util.Date;

import com.martin.dms.model.Client;
import com.martin.dms.model.Item;
import com.martin.dms.model.Purchase;

/**
 * Hibernate purchase implementation.
 * 
 * @author mtsvetkov
 */
public class PurchaseHib implements Purchase {

    private Long id;

    private Client client;
    private Item item;
    private int amount;
    private Date date;

    /**
     * Default constructor.
     */
    public PurchaseHib() {
    }

    /**
     * {@inheritDoc}
     */
    public Long getId() {
        return id;
    }

    /**
     * {@inheritDoc}
     */
    public Client getClient() {
        return client;
    }

    /**
     * Sets the client who made the purchase.
     * 
     * @param client - the client who made the purchase.
     */
    public void setClient(Client client) {
        this.client = client;
    }

    /**
     * {@inheritDoc}
     */
    public int getAmount() {
        return amount;
    }

    /**
     * Sets the amount of items purchased.
     * 
     * @param amount - the amount of items purchased.
     */
    public void setAmount(int amount) {
        this.amount = amount;
    }

    /**
     * {@inheritDoc}
     */
    public Date getDate() {
        return date;
    }

    /**
     * Sets the date of the purchase.
     * 
     * @param date - the date of the purchase.
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * {@inheritDoc}
     */
    public Item getItem() {
        return item;
    }

    /**
     * Sets the item that was purchased.
     * 
     * @param item - the purchased item.
     */
    public void setItem(Item item) {
        this.item = item;
    }

    /**
     * {@inheritDoc}
     */
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof PurchaseHib)) {
            return false;
        }
        final PurchaseHib purchase = (PurchaseHib) obj;
        if (purchase.getId() != null && this.getId() != null) {
            return purchase.getId().equals(this.getId());
        }
        return false;
    }

    /**
     * {@inheritDoc}
     */
    public int hashCode() {
        int result = 17;
        if (getId() != null) {
            result += 37 * result + getId().hashCode();
        }
        return result;
    }
}
